<?php

class History_model extends CI_Model {

	function __construct() {
		parent::__construct();
	}

	function get_successful_offers($fb_id) {
		$sql = "SELECT o.offer_id, o.item_title, o.item_desc, o.item_pic, o.fb_id, r.fb_id AS requester_fb_id FROM offer AS o JOIN request AS r ON o.offer_id = r.offer_id WHERE o.fb_id = ? AND r.status = ? AND o.status = ?";
		$query = $this->db->query($sql, array($fb_id, 'Closed', 'Closed'));
		
		$data = array();
		if($query->num_rows() > 0){
			foreach($query->result_array() AS $row){
				$data[] = $row;				
			}
		}
		return $data;
	}

	function get_successful_requests($fb_id) {
		$sql = "SELECT o.offer_id, o.item_title, o.item_desc, o.item_pic, o.fb_id, r.fb_id AS requester_fb_id FROM offer AS o JOIN request AS r ON o.offer_id = r.offer_id WHERE r.fb_id = ? AND r.status = ? AND o.status = ? ";
		$query = $this->db->query($sql, array($fb_id, 'Closed', 'Closed'));
		
		$data = array();
		if($query->num_rows() > 0){
			foreach($query->result_array() AS $row){
				$data[] = $row;				
			}
		}
		return $data;
	}
}

?>